package com.yitong.base.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class HttpUtil {
	
	@SuppressWarnings("unused")
	public static String doGet(String url, HttpServletRequest request) throws IOException{
		URL getUrl = new URL(url);
		HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
		connection.connect();
		Cookie[] cookie4= request.getCookies();
        String NL = System.getProperty("line.separator"); 
		BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));//设置编码,否则中文乱码
        StringBuffer sb = new StringBuffer("");  
        String lines=null;
		String content=null;
		while ((lines = reader.readLine()) != null){
				sb.append(lines + NL);  
				content = new String(lines.getBytes());
		}
		reader.close();
		// 断开连接
		connection.disconnect();
		return sb.toString();
	}
	
}
